﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.EmpbasicService;

namespace CommunitySystem.PageView
{
    public partial class BianZhiDetail_YiJieYongWindow : ChildWindow
    {
        private EmpbasicService.EmpBasicServiceClient Client = new EmpbasicService.EmpBasicServiceClient();
        public ObservableCollection<EmpbasicService.BianZhiModel> BianZhiModels =
            new ObservableCollection<EmpbasicService.BianZhiModel>();

        public BianZhiModel SelectItems;
        public int KeShiID;
        public string Jieyongqingkuang = "";
        public int ZhengFu = 0;
        public BianZhiDetail_YiJieYongWindow(string jieyongqingkuang, int keshiid,int zhengfu)
        {
            InitializeComponent();
            if(zhengfu > 0)
            {
                lb.Visibility = System.Windows.Visibility.Visible;
                lb1.Visibility = System.Windows.Visibility.Collapsed;
            }
            if (zhengfu < 0)
            {
                lb1.Visibility = System.Windows.Visibility.Visible;
                lb.Visibility = System.Windows.Visibility.Collapsed;
            }
            KeShiID = keshiid;
            Jieyongqingkuang = jieyongqingkuang;
            ZhengFu = zhengfu;
            Client.GetBianZhiDetail_YiJieYongModelCompleted 
                += new EventHandler<GetBianZhiDetail_YiJieYongModelCompletedEventArgs>(Client_GetBianZhiDetail_YiJieYongModelCompleted);
            Client.GetBianZhiDetail_YiJieYongModelAsync(keshiid, jieyongqingkuang, zhengfu);
            Client.CanTuiHuanZhiShuCompleted += new EventHandler<CanTuiHuanZhiShuCompletedEventArgs>(Client_CanTuiHuanZhiShuCompleted);
            Client.TuiHuanZhiShuCompleted += new EventHandler<TuiHuanZhiShuCompletedEventArgs>(Client_TuiHuanZhiShuCompleted);
        }

        void Client_TuiHuanZhiShuCompleted(object sender, TuiHuanZhiShuCompletedEventArgs e)
        {
            SilverlightMessageBoxLibrary.Message.InfoMessage("退还成功！");
            this.DialogResult = true;
        }

        void Client_CanTuiHuanZhiShuCompleted(object sender, CanTuiHuanZhiShuCompletedEventArgs e)
        {
            if(e.Result == true)
            {
                Client.TuiHuanZhiShuAsync(bianzhijieyongid,0);
            }
            else
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("该职位已安置人员，不可退还！");
            }
        }

        void Client_GetBianZhiDetail_YiJieYongModelCompleted(object sender, GetBianZhiDetail_YiJieYongModelCompletedEventArgs e)
        {
            lb.ItemsSource = null;
            lb.ItemsSource = e.Result;
            lb1.ItemsSource = null;
            lb1.ItemsSource = e.Result;
        }
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private int bianzhijieyongid = 0;
        private void zhengkerenshu_Click(object sender, RoutedEventArgs e)
        {
            HyperlinkButton hbtn = sender as HyperlinkButton;
            if (hbtn != null)
            {
                if (MessageBox.Show("确定退还该职数吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    bianzhijieyongid = Convert.ToInt32(hbtn.Tag);
                    Client.CanTuiHuanZhiShuAsync(bianzhijieyongid);
                }
            }
        }
    }
}
